const app = require('express')();
const http = require('http').createServer(app);

const io = require('socket.io')(http, {
  cors: {
    origin: "http://localhost:4200",
    methods: ["GET", "POST"],
    credentials: true
  }
});

io.on('connection', (socket) => {
  console.log('user connected');

  socket.on('disconnet', () => {
    console.log('user disconnected');
  });

  socket.on('add-message', (message) => {
    io.emit('message', message);
  });
})

http.listen(4000, () => {
  console.log('start on 4000....');
})
